package com.example.yiqingwaichu;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.json.JSONException;
import org.json.JSONObject;

public class dl extends AppCompatActivity {
    private EditText number, password1;
    private TextView tv_register;
    private int j = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        number = findViewById(R.id.number);
        password1 = findViewById(R.id.password);
        tv_register = findViewById(R.id.tv_register);

        tv_register.setOnClickListener(v -> {

            String moblile = number.getText().toString();
            String password = password1.getText().toString();

            if (moblile.isEmpty()) {
                Toast.makeText(this, "请输入手机号码", Toast.LENGTH_SHORT).show();
                return;
            }
            if (password.isEmpty()) {
                Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
                return;
            }


            tv_register.setEnabled(false);
            tv_register.setText("正在注册");

            String url = "http://xxs.lefx.top/zc.php?user=" + moblile + "&pass=" + password;

            OkGo.<String>get(url).execute(new StringCallback() {
                @Override
                public void onSuccess(Response<String> response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response.body());
                        Toast.makeText(dl.this, "注册成功", Toast.LENGTH_SHORT).show();
                        finish();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });


        });




    }
}
